package com.beta.cust.bind.datasync.utils;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Auther: pcc
 * @Date: 2024/3/16 15:38
 * @Description:
 */
public class CollectionUtil {

    public static <T> java.util.function.Predicate<T> distinctByKey(java.util.function.Function<? super T, Object> keyExtractor) {
        Map<Object, Boolean> seen = new ConcurrentHashMap<>();
        return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
    }
}
